package problem.year2022.April;

/**
 * @author Liu.Liangyuan
 * @version $Id: Day0415.java, v 0.1 2022年04月15日 1:40 下午 LiangMu Exp $$
 */

import java.util.ArrayList;
import java.util.List;

/**
 * // This is the interface that allows for creating nested lists.
 * // You should not implement it, or speculate about its implementation
 * public interface NestedInteger {
 *     // Constructor initializes an empty nested list.
 *     public NestedInteger();
 *
 *     // Constructor initializes a single integer.
 *     public NestedInteger(int value);
 *
 *     // @return true if this NestedInteger holds a single integer, rather than a nested list.
 *     public boolean isInteger();
 *
 *     // @return the single integer that this NestedInteger holds, if it holds a single integer
 *     // Return null if this NestedInteger holds a nested list
 *     public Integer getInteger();
 *
 *     // Set this NestedInteger to hold a single integer.
 *     public void setInteger(int value);
 *
 *     // Set this NestedInteger to hold a nested list and adds a nested integer to it.
 *     public void add(NestedInteger ni);
 *
 *     // @return the nested list that this NestedInteger holds, if it holds a nested list
 *     // Return empty list if this NestedInteger holds a single integer
 *     public List<NestedInteger> getList();
 * }
 */
public class Day0415 {
    public NestedInteger deserialize(String s) {
        // 如果不包含，则证明这是一个单值
        if (!s.contains("[")) {
            return new NestedInteger(Integer.parseInt(s));
        }
        char[] chars = s.toCharArray();
        NestedInteger result = new NestedInteger();
        List<NestedInteger> list = new ArrayList<>();

        result.setList(list);
        return result;
    }
}

class NestedInteger {
    private Integer value;
    private List<NestedInteger> list;

    public NestedInteger(Integer value, List<NestedInteger> list) {
        this.value = value;
        this.list = list;
    }

    public NestedInteger(Integer value) {
        this.value = value;
    }

    public NestedInteger() {
    }

    /**
     * Getter method for property value.
     *
     * @return property value of value
     */
    public Integer getValue() {
        return value;
    }

    /**
     * Setter method for property value.
     *
     * @param value value to be assigned to property value
     */
    public void setValue(Integer value) {
        this.value = value;
    }

    /**
     * Getter method for property list.
     *
     * @return property value of list
     */
    public List<NestedInteger> getList() {
        return list;
    }

    /**
     * Setter method for property list.
     *
     * @param list value to be assigned to property list
     */
    public void setList(List<NestedInteger> list) {
        this.list = list;
    }

    public boolean isInteger(){
        return value != null && list == null;
    }
}

